import 'dart:convert';

import 'package:enjoy_home/utils/http.dart';
import 'package:enjoy_home/utils/toast.dart';
import 'package:flutter/material.dart';
import 'package:flutter_html/flutter_html.dart';

class Detail extends StatefulWidget {
  const Detail({Key? key}) : super(key: key);

  @override
  _DetailState createState() => _DetailState();
}

class _DetailState extends State<Detail> {
  Map notifyDetail = {
    "id": "3",
    "content": "<p>尊敬的住户:</p>",
    "title": "小区关于办理业主卡的通知",
  };

  @override
  void didChangeDependencies() {
    super.didChangeDependencies();
    // 拿路由参数
    Map args = ModalRoute.of(context)!.settings.arguments as Map;
    print('路由参数:' + args.toString());
    if (args.isNotEmpty) {
      getNotifyDetail(args['id']);
    }
  }

  getNotifyDetail(String id) async {
    try {
      final res = await http.get('/announcement/$id');
      if (res['code'] != 10000) {
        return;
      }
      notifyDetail = res['data'];
    } catch (e) {
      ToastUtil.showInfo("网络请求错误！");
    }
  }

  @override
  Widget build(BuildContext context) {
    return Container(child: Html(data: notifyDetail['content']));
  }
}
